/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"B861DC72-BB1F-437B-ADB2-5DB1D4A9654A",variableType:4}
 */
var $historico = 0;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"019E3A8E-1C6D-4ED4-B5B0-BFC838A8D55E",variableType:4}
 */
var $historico_listado_perfiles = 1;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"3F9A9D7F-13B3-4EFB-96AC-0C19F83C7F29",variableType:4}
 */
var $historico_listado_usuarios = 2;

/**
 * @properties={typeid:24,uuid:"6D4E44A6-FD7F-44C8-A06A-4841C7483807"}
 */
function doEdit(){
	
	if (foundset.getSelectedRecord().isNew()){
		elements.historicos.visible = false;
		elements.btn_alta_historicos.visible = false;
		elements.btn_menu_historicos.visible = false;
		elements.tab_historicos.visible = false;
	}else{
		elements.historicos.visible = true;
		elements.btn_alta_historicos.visible = true;
		elements.btn_menu_historicos.visible = true;
		elements.tab_historicos.visible = true;
	}
	
	elements.historicos.enabled = false;
	elements.btn_alta_historicos.enabled = false;
	elements.btn_menu_historicos.enabled = false;
	elements.tab_historicos.enabled = false;
	controller.focusField(elements.fld_s_descripcion.getName(),true);
}

/**
 * @properties={typeid:24,uuid:"95428D8D-FB7E-4C56-BA60-4BBA9D06DDB5"}
 */
function hide_btn_reset_fields(){
	
	elements.historicos.enabled = true;
	elements.btn_alta_historicos.enabled = true;
	elements.btn_menu_historicos.enabled = true;
	elements.tab_historicos.enabled = true;
}

/**
 * Opciones propias del menú
 * @author Roberto J. Blasco
 * @version 1.0
 * @param event
 *
 * @properties={typeid:24,uuid:"4CFA0D49-FFBF-457A-AAD5-3E6EA56A5C07"}
 */
function opciones(event){
	
	var submenu_alta_perfil = $menu.addMenuItem("Alta Perfil", alta_perfil);
	submenu_alta_perfil.methodArguments = [event, foundset.getSelectedRecord()];
	var submenu_alta_usuario = $menu.addMenuItem("Alta Usuario", alta_usuario);
	submenu_alta_usuario.methodArguments = [event, foundset.getSelectedRecord()];
}

/**
 * Alta de un nuevo Perfil
 * @author Roberto J. Blasco
 * @version 1.0
 * @private 
 * @properties={typeid:24,uuid:"3D7F4C94-013D-4B83-B0F0-CE1883C24CBD"}
 */
function alta_perfil(){
	
	
}

/**
 * Alta de un nuevo Usuario
 * @author Roberto J. Blasco
 *  @version 1.0
 *  @private 
 * @properties={typeid:24,uuid:"DD656916-BE22-4223-9EFF-B9B74AA881D8"}
 */
function alta_usuario(){
	
	
}

/**
 * Handle changed data.
 *
 * @param {Number} oldValue old value
 * @param {Number} newValue new value
 * @param {JSEvent} event the event that triggered the action
 *
 * @returns {Boolean}
 *
 * @private
 *
 * @properties={typeid:24,uuid:"CEB10DB7-B701-4430-AF45-F4C9779CE560"}
 */
function onDataChangeHistorico(oldValue, newValue, event) {

	elements.tab_historicos.removeAllTabs();
	if ($historico == $historico_listado_perfiles){
		elements.tab_historicos.addTab(forms.lst_adm_t900_perfiles_h,null,null,null,null,null,null, adm_t900_empresas_to_adm_t900_perfiles);
	}else if  ($historico == $historico_listado_usuarios){
		elements.tab_historicos.addTab(forms.lst_adm_t900_usuarios_h,null,null,null,null,null,null, adm_t900_empresas_to_adm_t900_usuarios);
	}
	return true
}

/**
 * Callback method for when form is shown.
 * @author Roberto J. Blasco
 * @version 1.0
 * @param {Boolean} firstShow form is shown first time after load
 * @param {JSEvent} event the event that triggered the action
 * @private
 * @properties={typeid:24,uuid:"299AEB3E-7EDC-4053-9BF8-FDA6F19148A2"}
 */
function onShow(firstShow, event) {

	if (foundset.getSelectedRecord().isNew()){
		elements.tab_historicos.visible = false;
	}else{
		
		var dataset = databaseManager.createEmptyDataSet(0,new Array('display_values','optional_real_values'));
		dataset.addRow(['LISTADO DE PERFILES', $historico_listado_perfiles]);
		dataset.addRow(['LISTADO DE USUARIOS', $historico_listado_usuarios]);
		elements.historicos.setValueListItems(dataset);
		
		elements.tab_historicos.visible = true;
		elements.tab_historicos.removeAllTabs();
		elements.tab_historicos.addTab(forms.lst_adm_t900_perfiles_h,null,null,null,null,null,null,adm_t900_empresas_to_adm_t900_perfiles);
		$historico = $historico_listado_perfiles;
	}
}

/**
 * @param {JSEvent} event
 * @properties={typeid:24,uuid:"721571FC-A03C-43CF-8329-2754D1D3CAE1"}
 */
function eliminar_antes(event){
	
	var error = "";
	
	if (utils.hasRecords(foundset.getSelectedRecord().adm_t900_empresas_to_adm_t900_perfiles)){
		error += "La empresa tiene " +  adm_t900_empresas_to_adm_t900_perfiles.historico + " Perfiles. Si continúa, serán eliminados.";
	}
	
	if (utils.hasRecords(foundset.getSelectedRecord().adm_t900_empresas_to_adm_t900_usuarios)){
		error += "La empresa tiene " + adm_t900_empresas_to_adm_t900_usuarios.historico + " Usuarios. Si continúa, serán eliminados";
	}
	
	globals.$error = error;
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"391F644C-DBA8-469E-B1CD-69EC6E0A474F"}
 */
function historico_opciones(event) {
	// TODO Auto-generated method stub
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"DF3932FD-DFA9-4D4D-8FA9-381109029B2F"}
 */
function historico_alta(event) {

	/** @type {JSDataSet} */
	var ds = databaseManager.createEmptyDataSet();
	ds.addRow(['adm_t900_empresas_id', adm_t900_empresas_id]);
	ds.addRow(['adm_t900_aplicaciones_id', adm_t900_empresas_to_adm_t300_apli_emp.adm_t300_apli_emp_to_adm_t900_aplicaciones.adm_t900_aplicaciones_id]);
	
	if ($historico == $historico_listado_perfiles){
		globals.ir_formulario(event, forms.frm_adm_t900_perfiles.controller.getName(), null, globals.$MODO_ALTA,ds);
	}else if ($historico == $historico_listado_usuarios){
		globals.ir_formulario(event, forms.frm_adm_t900_usuarios.controller.getName(), null,  globals.$MODO_ALTA,ds);
	}
}